/*
* @Date: 2021/3/25
* @Author: XueChengwu <xuechengwu@erayt.com>
* @Copyright: 2015-2019 Erayt, Inc.
* @Description: If you have some questions, please contact: xuechengwu@erayt.com.
*/
import Layer from '../core/Layer';
import Line from '../base/Line';
import Point from '../core/Point';
export default class extends Layer {
  constructor(canvas, style) {
    super(canvas, style);
    this.rows = style.rows || 3;
    this.cols = style.cols || 3;
  }

  build(painter) {
    this.clearEventListener();
    this.childs.splice(0, this.childs.length);
    let rowStep = this.height / this.rows;
    let colStep = this.width / this.cols;
    for (let i = 0; i <= this.rows; i++) {
      let line = new Line(this.canvas, {
        ...this,
        left: 0,
        bottom: i * rowStep,
        position: 'absolute',
        from: new Point(0, 0),
        to: new Point(this.width, 0),
      });
      this.addChild(line);
    }
    for (let i = 0; i <= this.cols; i++) {
      let line = new Line(this.canvas, {
        ...this,
        left: i * colStep,
        bottom: 0,
        from: new Point(0, 0),
        to: new Point(0, this.height),
        position: 'absolute',
      });
      this.addChild(line);
    }
  }
}
